require('./mongoose')
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var datatypeSchema = Schema({
  value: { type: String, unique: true },
  label: { type: String }
})

datatypeSchema.statics = {
  init: function () {
    // 暂内置4种基本数据类型
  	var list = [
      {"value":"string","label":"字符串"},
      {"value":"number","label":"数值"},
      {"value":"date","label":"日期"},
      {"value":"bool","label":"布尔"},
      {"value":"enum","label":"枚举"},
      {"value":"datasource","label":"数据源"},
      {"value":"foreign","label":"外键"}
    ]
    Datatype.count((err, count) => {
      if(count == 0) {
        Datatype.create(list);
      }
    })
  }
}

var Datatype = mongoose.model('Datatype', datatypeSchema);

module.exports = Datatype
